package com.qfedu.lc.server.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qfedu.lc.server.entity.UserVipOrder;
import com.qfedu.lc.server.mapper.UserVipOrderMapper;
import com.qfedu.lc.server.service.UserVipOrderService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * 9.用户vip订单表 服务实现类
 * </p>
 *
 * @author wgz
 * @since 2023-11-06
 */
@Service
public class UserVipOrderServiceImpl extends ServiceImpl<UserVipOrderMapper, UserVipOrder> implements UserVipOrderService {


    @Resource
    private UserVipOrderMapper vipOrderMapper;

    @Override
    public boolean addOrder(UserVipOrder userVipOrder) {

        int num = vipOrderMapper.insert(userVipOrder);
        if (num>0){
            return  true;
        }

        return false;
    }

    @Override
    public boolean updateUserVipOrder(String no, int status) {

        // 根据订单号查询订单
        QueryWrapper<UserVipOrder> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("no",no);
        UserVipOrder userVipOrder = vipOrderMapper.selectOne(queryWrapper);

        userVipOrder.setStatus(status);// 已支付

        int num = vipOrderMapper.updateById(userVipOrder);
        if (num>0){
            return true;
        }

        return false;
    }
}
